{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "from xtquant.xttrader import XtQuantTrader\n",
    "from xtquant import xtdata\n",
    "\n",
    "# miniQMT安装路径\n",
    "mini_qmt_path = r'D:\\国金QMT交易端模拟\\userdata_mini'\n",
    "# 创建session_id\n",
    "session_id = int(random.randint(100000, 999999))\n",
    "# 创建交易对象\n",
    "xt_trader = XtQuantTrader(mini_qmt_path, session_id)\n",
    "# 启动交易对象\n",
    "xt_trader.start()\n",
    "# 连接客户端\n",
    "connect_result = xt_trader.connect()\n",
    "\n",
    "if connect_result == 0:\n",
    "    print('连接成功')\n",
    "\n",
    "from xtquant.xttype import StockAccount\n",
    "# QMT账号\n",
    "account_id = '39020958'\n",
    "# 创建账号对象\n",
    "account = StockAccount(account_id)\n",
    "# 订阅账号\n",
    "res = xt_trader.subscribe(account)\n",
    "print(account)\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trades = xt_trader.query_stock_trades(account)\n",
    "print(\"trades:\", len(trades))\n",
    "print('连接成功')\n",
    "for trade in trades:\n",
    "    print('账号类型:', trade.account_type)\n",
    "    print('资金账号:', trade.account_id)\n",
    "    print('证券代码:', trade.stock_code)\n",
    "    print('委托类型:', trade.order_type)\n",
    "    print('成交编号:', trade.traded_id)\n",
    "    print('成交时间:', trade.traded_time)\n",
    "    print('成交均价:', trade.traded_price)\n",
    "    print('成交数量:', trade.traded_volume)\n",
    "    print('成交金额:', trade.traded_amount)\n",
    "    print('订单编号:', trade.order_id)\n",
    "    print('柜台合同编号:', trade.order_sysid)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
